Fix wildcard exports extensionless resolution in bundler mode#62911
Open
Scalahansolo wants to merge 1 commit intomicrosoft:mainfrom
Open
Fix wildcard exports extensionless resolution in bundler mode#62911Scalahansolo wants to merge 1 commit intomicrosoft:mainfrom
Scalahansolo wants to merge 1 commit intomicrosoft:mainfrom
Conversation
When using moduleResolution: 'bundler' with wildcard exports patterns like "./*": "./src/*", extensionless imports (e.g., import from "pkg/utils") now correctly resolve to TypeScript files (e.g., ./src/utils.ts). The fix adds extension probing specifically in the exports/imports resolution path (loadModuleFromTargetExportOrImport) for extensionless paths in bundler mode, rather than modifying the general loadFileNameFromPackageJsonField function which would cause duplicate lookups in other code paths. Fixes microsoft#62909
a4294f6 to
d7080f7
Compare
Author
|
@microsoft-github-policy-service agree company="Linear" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #62909
When using
moduleResolution: "bundler"with wildcard exports patterns like"./*": "./src/*", extensionless imports (e.g.,import from "@repo/library/utils") now correctly resolve to TypeScript files (e.g.,./src/utils.ts).Problem
Previously,
loadFileNameFromPackageJsonFieldwould returnundefinedfor extensionless paths without attempting to add extensions, even in bundler mode where extensionless imports are supposed to work. This caused imports like:to fail with
TS2307: Cannot find module '@repo/library/utils'when the package.json had:{ "exports": { "./*": "./src/*" } }Solution
Modified
loadFileNameFromPackageJsonField()insrc/compiler/moduleNameResolver.tsto add extension probing (.ts,.tsx,.d.ts,.js,.jsx) for extensionless paths when not in ESM mode. This mirrors the existing behavior ofloadModuleFromFile()for regular imports.The fix only affects bundler mode -
node16andnodenextmodes continue to require explicit extensions as expected.Changes
Code Change
src/compiler/moduleNameResolver.ts: Added fallback totryAddingExtensions()for extensionless paths in non-ESM modeNew Tests
bundlerWildcardExportsExtensionResolution.ts: Tests that wildcard exports resolve extensionless imports in bundler modenode16WildcardExportsRequiresExtension.ts: Verifies node16 mode still requires extensions (negative test)wildcardExportsBundlerExtensionlessResolution.ts: Fourslash test for quickInfo on resolved importsUpdated Baselines
Several trace baselines updated to reflect the additional extension probing that now occurs for extensionless paths in package.json fields.